'use strict';

module.exports = app => {
  const DataTypes = app.Sequelize;
  const sequelize = app.model;
  const attributes = {
    id: {
      type: DataTypes.INTEGER(10).UNSIGNED,
      allowNull: false,
      defaultValue: null,
      primaryKey: true,
      autoIncrement: true,
      comment: null,
      field: "id"
    },
    upload_path_id: {
      type: DataTypes.INTEGER(10).UNSIGNED,
      allowNull: false,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: null,
      field: "upload_path_id"
    },
    mime_type: {
      type: DataTypes.STRING(63),
      allowNull: false,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "文件类型",
      field: "mime_type"
    },
    filename: {
      type: DataTypes.STRING(63),
      allowNull: false,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "文件名",
      field: "filename"
    },
    encoding: {
      type: DataTypes.STRING(63),
      allowNull: false,
      defaultValue: "7bit",
      primaryKey: false,
      autoIncrement: false,
      comment: "编码：'7bit'",
      field: "encoding"
    },
    fieldname: {
      type: DataTypes.STRING(63),
      allowNull: true,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "文件描述字段",
      field: "fieldname"
    },
    create_time: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: sequelize.literal('CURRENT_TIMESTAMP'),
      primaryKey: false,
      autoIncrement: false,
      comment: null,
      field: "create_time"
    },
    update_time: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: sequelize.literal('CURRENT_TIMESTAMP'),
      primaryKey: false,
      autoIncrement: false,
      comment: null,
      field: "update_time"
    },
    status: {
      type: DataTypes.ENUM('0', '1'),
      allowNull: false,
      defaultValue: "1",
      primaryKey: false,
      autoIncrement: false,
      comment: null,
      field: "status"
    }
  };
  const options = {
    tableName: "file",
    comment: "",
    indexes: [],
    createdAt: "create_time",
    updatedAt: "update_time",
  };
  const FileModel = sequelize.define("file_model", attributes, options);

  FileModel.associate = function() {
    app.model.File.belongsTo(
      app.model.UploadPath,
      { foreignKey: "upload_path_id" }
    )
  }
  
  return FileModel;
};